home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu332 / 332doc.arc / 332BUGC3 < prev    next >
Text File  |  1989-12-19  |  20KB  |  556 lines

  1.                                                                       
  2.   DEBUG MONITOR USER'S MANUAL    MOTOROLA
  3.   4-1     M68332BUG
  4.  
  5.                                                                       
  6.   DEBUG MONITOR USER'S MANUAL    MOTOROLA
  7.   M68332BUG    4-1
  8.  
  9.  
  10. CHAPTER 4
  11.  
  12. USING THE ONE-LINE ASSEMBLER/DISASSEMBLER
  13.  
  14.  
  15.  
  16. 4.1  INTRODUCTION
  17.  
  18. Included as part of the 332Bug firmware is a one-line assembler/disassembler function.  The 
  19. assembler is an interactive assembler/editor in which the source program is not saved.  Each 
  20. source line is translated into MC68332 machine language code and is stored line-by-line into 
  21. memory as it is entered.  In order to display an instruction, the machine code is disassembled 
  22. and the instruction mnemonic and operands are displayed.  All valid MC68332 instructions 
  23. are translated.
  24.  
  25. The 332Bug assembler is effectively a subset of the MC68332 resident structured assembler.  
  26. It has some limitations as compared with the resident assembler, such as not allowing line 
  27. numbers and labels; however, it is a powerful tool for creating, modifying, and debugging 
  28. MC68332 code.
  29.  
  30.  
  31. 4.1.1  MC68332 Assembly Language
  32.  
  33. MC68332 assembly language is the symbolic language used to code source programs for 
  34. processing by the assembler. This language is a collection of mnemonics representing:
  35.  
  36. Ñ    Operations
  37.         MC68332 machine-instruction operation code
  38.         Directives (pseudo-ops)
  39. Ñ    Operators
  40. Ñ    Special symbols
  41.  
  42.  
  43. 4.1.1.1  Machine-Instruction Operation Codes.  The part of the assembly language 
  44. that provides the mnemonic machine-instruction operation codes for the MC68332 machine 
  45. instructions are described in the CPU32 Reference Manual.  Refer to that manual for any 
  46. questions concerning operation codes.
  47.  
  48.  
  49. 4.1.1.2  Directives.  Normally, assembly language can contain mnemonic directives 
  50. which specify assembler auxiliary action.  The 332Bug assembler recognizes only two 
  51. directives: DC.W (define constant) and SYSCALL.  These two directives define data within 
  52. the program and make 332Bug utility calls (refer to paragraphs 4.2.3 and 4.2.4, respectively).
  53.  
  54. 4.1.2  MC68332 Resident Structured Assembler Comparison
  55.  
  56. There are several major differences between the 332Bug assembler and the MC68332 
  57. resident structured assembler.  The resident assembler is a two-pass assembler that 
  58. processes an entire program as a unit, while the 332Bug assembler processes each line of a 
  59. program as an individual unit.  Due mainly to this basic functional difference, the 332Bug 
  60. assembler capabilities are more restricted:
  61.  
  62. Ñ    Label and line numbers are not used.  Labels are used to reference other lines and 
  63. locations in a program.  The one-line assembler has no knowledge of other lines 
  64. and, therefore, cannot make the required association between a label and the label 
  65. definition located on a separate line.
  66.  
  67. Ñ    Source lines are not saved.  In order to read back a program after it is entered, the 
  68. machine code is disassembled and then displayed as mnemonics and operands.
  69.  
  70. Ñ    Only two directives (DC.W and SYSCALL) are accepted.
  71.  
  72. Ñ    No macro operation capability is included.
  73.  
  74. Ñ    No conditional assembly is used.
  75.  
  76. Ñ    No structured assembly is used.
  77.  
  78. Ñ    Several symbols recognized by the resident assembler are not included in the 
  79. 332Bug assembler character set.  These symbols include ''>'' and ''<''.  Three other 
  80. symbols have multiple meaning to the resident assembler, depending on the context.  
  81. These are:
  82.  
  83.     Asterisk (*)    -    Multiply or current PC
  84.     Slash (/)    -    Divide or delimiter in a register list
  85.     Ampersand (&)    -    And or decimal number prefix
  86.  
  87. Although functional differences exist between the two assemblers, the one-line assembler is 
  88. a true subset of the resident assembler.  The 332Bug assembler format and syntax are 
  89. acceptable to the resident assembler except as described above.
  90.  
  91.  
  92. 4.2  SOURCE PROGRAM CODING
  93.  
  94. A source program is a sequence of source statements arranged in a logical manner to 
  95. perform predetermined tasks. Each source statement occupies a line and must be either an 
  96. executable instruction, a DC.W directive, or a SYSCALL assembler directive.  Each source 
  97. statement follows a consistent source line format.
  98.  
  99. 4.2.1  Source Line Format
  100.  
  101. Each source statement is a combination of operation and, as required, operand fields.  Line 
  102. numbers, labels and comments are not used.
  103.  
  104. 4.2.1.1  Operation Field.  Since there is no label field, the operation field may begin in 
  105. the first available column.  It may also follow one or more spaces.  Entries can consist of one 
  106. of three categories:
  107.  
  108. Ñ    Operation codes which correspond to the MC68332 instruction set.
  109. Ñ    Define constant directive (DC.W) defines a constant in a word location.
  110. Ñ    System call directive (SYSCALL) calls 332Bug system utilities.
  111.  
  112. The size of the data field affected by an instruction is determined by the data size codes.  
  113. Some instructions and directives can operate on more than one data size.  For these 
  114. operations, the data size code must be specified or a default size applicable to the instruction 
  115. is used. The size code need not be specified if only one data size is permitted by an 
  116. operation.  The operation field is followed by a period (.) and the data size code.  The data 
  117. size codes are:
  118.  
  119.  
  120.     B    = Byte (8-bit data)
  121.     W    = Word (16-bit data; the usual default size)
  122.     L    = Longword (32-bit data)
  123.  
  124.  
  125. When the instruction or directive does not have a data size attribute, the data size code is not 
  126. permitted.
  127.  
  128.  
  129. EXAMPLES:  Legal
  130.  
  131. LEA    (A0),A1    Load the effective address of the first operand into A1.  The 
  132. longword size is the default (.B, .W not allowed) for this 
  133. instruction
  134.  
  135. ADD.B    (A0),D0    Add the byte pointed to in A0 to the lowest order byte in D0.
  136.  
  137. ADD    D1,D2    Add the low order word of D1 to the low order word of D2.  W is 
  138. the default size code for ADD.
  139.  
  140. ADD.L    A3,D3    Add the entire 32-bit (longword) contents of A3 to D3.
  141.  
  142.  
  143. EXAMPLE:  Illegal:
  144.  
  145. SUBA.B    #5,A1    Illegal size specification (.B not allowed in instruction SUBA).  
  146. This instruction would have subtracted the value 5 from the low 
  147. order byte of A1; byte operations on address registers are not 
  148. allowed.
  149.  
  150.  
  151. 4.2.1.2  Operand Field.  If present, the operand field follows the operation field and is 
  152. separated from the operation field by at least one space.  When two or more operand 
  153. subfields appear within a statement, separate them with a comma.  In an instruction like 'ADD 
  154. D1,D2', the first subfield (D1) is called the source effective address (<EA>) field, and the 
  155. second subfield (D2) is called the destination <EA> field.  Thus, the contents on D1 are 
  156. added to the contents of D2 and the result saved in register D2.  In the instruction 'MOVE 
  157. D1,D2', the first subfield (D1) is the source field and the second subfield (D2) is the 
  158. destination field.  In other words, for most two-operand instructions, the format '<opcode> 
  159. <source>,<destination>' applies.
  160.  
  161.  
  162. 4.2.1.3  Disassembled Source Line.  The disassembled source line may not look 
  163. identical to the source line entered.  The disassembler decides how to interpret the numbers 
  164. used.  If the number is an offset of an address register, it is treated as a signed hexadecimal 
  165. offset. Otherwise, it is treated as a straight unsigned hexadecimal.
  166.  
  167.  
  168. EXAMPLE:
  169.  
  170.     MOVE.L    #1234,5678
  171.     MOVE.L    FFFFFFFC(A0),5678
  172.  
  173.  
  174. disassembles to
  175.  
  176. 00003000    21FC0000 12345678    MOVE.L    #$1234,($5678).W
  177. 00003008    21E8FFFC 5678    MOVE.L    -$4(A0),($5678).W
  178.  
  179.  
  180. Also, for some instructions, there are two valid mnemonics for the same opcode, or there is 
  181. more than one assembly language equivalent.  When the opcode is disassembled some 
  182. instructions may appear different from the originally entered code.  As examples:
  183.  
  184.     BT is dissembled as BRA
  185.     DBRA is dissembled as DBF
  186.  
  187.  
  188.  
  189.  
  190. NOTE
  191.  
  192. The assembler recognizes two forms of mnemonics for two branch instructions.  
  193. The BT form (branch conditionally true) has the same opcode as the BRA 
  194. instruction.  Also, DBRA (decrement and branch always) and DBF (never true, 
  195. decrement, and branch) mnemonics are different forms for the same instruction.  
  196. In each case, the assembler accepts both forms.
  197.  
  198.  
  199.  
  200. 4.2.1.4  Mnemonics and Delimiters.  The assembler recognizes all MC68332 
  201. instruction mnemonics.  Numbers are recognized as binary, octal, decimal, and hexadecimal, 
  202. with hexadecimal as the default case.
  203.  
  204. Ñ    Decimal values are preceded by an ampersand (&).  Examples are:
  205.  
  206.     &12334
  207.     -&987654321
  208.  
  209.  
  210. Ñ    Hexadecimal values are preceded by a dollar sign ($).  An example is:
  211.  
  212.     $AFE5
  213.  
  214.  
  215. One or more ASCII characters enclosed by single quote marks ( ' ) constitute an ASCII string.  
  216. ASCII strings are right-justified and zero filled (if necessary), whether stored or used as 
  217. immediate operands.
  218.  
  219.  
  220. 00003000    21FC0000 12345678    MOVE.L    #$1234,($5678).W
  221. 005000    0053    DC.W    'S'
  222. 005002    223C41424344    MOVE.L    #'ABCD',D1
  223. 005008    3536    DC.W    '56'
  224.  
  225.  
  226. The following register mnemonics are recognized/referenced by the 
  227. assembler/disassembler:
  228.  
  229.  
  230. Pseudo Registers
  231.  
  232. R0-R7    User Offset Registers.
  233.  
  234.  
  235. Main Processor Registers
  236. PC    Program Counter - Used only in forcing program counter-relative 
  237. addressing.
  238. SR    Status Register
  239. CCR    Condition Codes Register (Lower eight bits of SR)
  240. USP    User Stack Pointer
  241. SSP    System Stack Pointer
  242.  
  243. Main Processor Registers (cont'd)
  244. VBR    Vector Base Register
  245. SFC    Source Function Code Register
  246. DFC    Destination Function Code Register
  247. D0-D7    Data Registers
  248. A0-A7    Address Registers - Address register A7 represents the active system 
  249. stack pointer, that is, either USP or SSP, as specified by the S bit of the 
  250. status register 
  251.  
  252.  
  253. 4.2.1.5  Character Set.  The character set recognized by the 332Bug assembler is a 
  254. subset of ASCII and listed below:
  255.  
  256.     Ñ    The letters A through Z (uppercase and lowercase)
  257.     Ñ    The integers 0 through 9
  258.     Ñ    Arithmetic operators:  +, -, *, /, <<, >>, !, &
  259.     Ñ    Parentheses ( )
  260.     Ñ    Characters used as special prefixes:
  261.             # (pound sign) specifies the immediate form of addressing.
  262.             $ (dollar sign) specifies a hexadecimal number.
  263.             & (ampersand) specifies a decimal number.
  264.             @ (commercial at sign) specifies an octal number.
  265.             % (percent sign) specifies a binary number.
  266.             ' (apostrophe) specifies an ASCII literal character string.
  267.     Ñ    Five separating characters:
  268.             Space
  269.             . (period)
  270.             / (slash)
  271.             - (dash)
  272.     Ñ    The asterisk (*) character indicates current location.
  273.  
  274.  
  275. 4.2.2  Addressing Modes
  276.  
  277. Effective address modes, combined with operation codes, define the particular function 
  278. performed by a given instruction.  Effective addressing and data organization are described 
  279. in detail in the CPU32 Reference Manual.
  280.  
  281. Table 4-1 summarizes the 332Bug one-line assembler addressing modes.
  282.  
  283.  
  284. TABLE 4-1.  332Bug Assembler Addressing Modes
  285.  
  286.     FORMAT    DESCRIPTION
  287.  
  288.     Dn    Data register direct
  289.     An    Address register direct
  290.     (An)    Address register indirect
  291.     (An)+    Address register indirect with post-increment
  292.     -(An)    Address register indirect with pre-decrement
  293.     d(An)    Address register indirect with displacement
  294.     d(An,Xi)    Address register indirect with index, 8-bit displacement
  295.     (bd,An,Xi)    Address register indirect with index, base displacement
  296.     ADDR(PC)    Program counter indirect with displacement
  297.     ADDR(PC,Xi)    Program counter indirect with index, 8-bit displacement
  298.     (ADDR,PC,Xi)    Program counter indirect with index, base displacement
  299.     (xxxx).W    Absolute word address
  300.     (xxxx).L    Absolute long address
  301.     #xxxx    Immediate data
  302.  
  303.  
  304.  
  305.  
  306. The user may use an expression in any numeric field of these addressing modes. The 
  307. assembler has a built in expression evaluator that supports the following operand types and 
  308. operators:
  309.  
  310.     Binary numbers    (%10   )
  311.     Octal numbers    (@76543210)
  312.     Decimal numbers    (&9876543210)
  313.     Hexadecimal numbers    ($FEDCBA9876543210)
  314.     String literals    ('CHAR' )
  315.     Offset registers    (R0-R7)
  316.     Program counter    (*)
  317.  
  318.  
  319. Allowed operators are:
  320.  
  321.     Addition    +
  322.     Subtraction    -
  323.     Multiply    *
  324.     Divide    /
  325.     Shift left    <<
  326.     Shift right    >>
  327.     Bitwise or    !
  328.     Bitwise and    &
  329.  
  330.  
  331. The order of evaluation is strictly left to right with no precedence granted to some operators 
  332. over others.  The only exception is when the user forces the order of precedence via the use 
  333. of parentheses.
  334.  
  335. Possible points of confusion:
  336.  
  337. Ñ    Differentiate numbers and registers to avoid confusion.  For example:
  338.  
  339.     CLR    D0     means CLR.W register D0. On the other hand,
  340.  
  341.     CLR    $D0
  342.     CLR    0D0
  343.     CLR    +D0
  344.     CLR    D0+0    all mean CLR.W memory location $D0.
  345.  
  346. Ñ    With the use of asterisk (*) to represent both multiply and program counter, 
  347. how does the assembler know when to use which definition?
  348.  
  349. For parsing algebraic expressions, the order of parsing is
  350.  
  351.     <OPERAND> <OPERATOR> <OPERAND> <OPERATOR>
  352.  
  353. with a possible left or right parenthesis.
  354.  
  355. Given the above order, the assembler can distinguish by placement 
  356. which definition to use. For example:
  357.  
  358.     ***    Means    PC    *    PC
  359.     *+*    Means    PC    +    PC
  360.     2**    Means    2    *    PC
  361.     *&&16    Means    PC    AND    &16
  362.  
  363.  
  364. When specifying operands, the user may skip or omit entries with the following addressing 
  365. modes.
  366.  
  367.     Ñ    Address register indirect with index, base displacement.
  368.     Ñ    Program counter indirect with index, base displacement.
  369.  
  370.  
  371. For the above modes, the rules for omission/skipping are as follows:
  372.  
  373. Ñ    The user may terminate the operand by specifying '')''.
  374.  
  375.     EXAMPLE:
  376.     CLR    ( ) or
  377.     CLR     (,,) is equivalent to
  378.     CLR    (0.N,ZA0,ZD0.W*1)
  379.  
  380. Ñ    The user may skip a field by stepping past it with a comma.
  381.  
  382.     EXAMPLE:
  383.     CLR    (D7) is equivalent to
  384.     CLR    ($D7,ZA0,ZD0.W*1)
  385.     but
  386.     CLR    (,,D7) is equivalent to
  387.     CLR    (0.N,ZA0,D7.W*1)
  388.  
  389. Ñ    If the user does not specify the base register, the default is ''ZA0''.  When Z precedes 
  390. the register number, it indicates that register is suppressed.
  391.  
  392. Ñ    If the user does not specify the index register, the default is ''ZD0.W*1''.
  393.  
  394. Ñ    Any unspecified displacements are defaulted to ''0''.
  395.  
  396.  
  397. 4.2.3  Define Constant Directive (DC.W)
  398.  
  399. The format for the DC.W directive is:
  400.     DC.W <operand >
  401.  
  402. This directive defines a constant in memory.  The DC.W directive has only one operand (16-
  403. bit value) which can contain the actual value (decimal, hexadecimal, or ASCII).  Alternatively, 
  404. the operand can be an expression which is assigned a numeric value by the assembler.  The 
  405. constant is aligned on a word boundary if word (.W) size is specified.  An ASCII string is 
  406. recognized when characters are enclosed inside single quotes marks (' . . . ').  Each 
  407. character (7 bits) is assigned to a byte of memory with the eighth bit (MSB) always equal to 
  408. zero.  If only one byte is entered, the byte is right justified.  A maximum of two ASCII 
  409. characters may be entered for each DC.W directive.
  410.  
  411. EXAMPLES:
  412. 00010022    04D2    DC.W    1234    Decimal number
  413. 00010024    AAFE    DC.W    &AAFE    Hexadecimal number
  414. 00010026    4142    DC.W    'AB'    ASCII String
  415. 00010028    5443    DC.W    'TB'+1    Expression
  416. 0001002A    0043    DC.W    'C'    ASCII character is right justified
  417.  
  418.  
  419. 4.2.4  System Call Directive (SYSCALL)
  420.  
  421. This directive aids the user in making the TRAP #15 calls to the system functions.  The format 
  422. for this directive is:
  423.     SYSCALL <function name >
  424. For example, the following two pieces of code produce identical results.
  425.  
  426.  
  427.     TRAP    #$F
  428.     DC.W    0
  429. or
  430.     SYSCALL    .INCHR
  431.  
  432.  
  433. Refer to Chapter 5 (SYSTEM CALLS), for a complete listing of all the functions provided.
  434.  
  435.  
  436. 4.3  ENTERING AND MODIFYING SOURCE PROGRAM
  437.  
  438. User programs are entered into memory using the one-line assembler/disassembler.  The 
  439. program is entered in assembly language statements on a line-by-line basis.  The source 
  440. code is not saved as it is converted immediately upon entry into machine code.  This imposes 
  441. several restrictions on the type of source line that can be entered.
  442.  
  443. Symbols and labels, other than the defined instruction mnemonics, are not allowed.  The 
  444. assembler has no means of storing the associated values of the symbols and labels in 
  445. lookup tables. This forces the programmer to use memory addresses and to enter data 
  446. directly rather than use labels.
  447.  
  448. Also, editing is accomplished by retyping an entirely new source line.  Add or delete lines by 
  449. moving a block of memory data to free up or delete the appropriate number of locations (refer 
  450. to the BM command).
  451.  
  452. 4.3.1  Executing the Assembler/Disassembler
  453.  
  454. The assembler/disassembler is actuated using the ;DI option of the MM (Memory Modify) and 
  455. MD (Memory Display) commands:
  456.  
  457.     MM <ADDR >;DI
  458. where
  459.     <CR>    sequences to next instruction
  460.     .<CR>    exits command
  461. and
  462.     MD[S] <ADDR>[:<count>I<ADDR>];DI
  463.  
  464.  
  465. Use the MM (;DI option) to enter and modify the program.  When this command is used, the 
  466. memory contents at the specified location are disassembled and displayed.  A new or 
  467. modified line can be entered if desired.
  468.  
  469. The disassembled line is either an MC68332 instruction, a SYSCALL, or a DC.W directive.  If 
  470. the disassembler recognizes a valid form of an instruction, the instruction is returned.  If the 
  471. disassembler does not recognizes a valid form of an instruction, random data occurs, the 
  472. DC.W $XXXX (always hex) is returned.  Because the disassembler gives precedence to 
  473. instructions, a word of data interpreted as a valid instruction is returned as the instruction.
  474.  
  475. 4.3.2  Entering a Source Line
  476.  
  477. Enter a new source line immediately following the disassembled line.  Use the format 
  478. discussed in paragraph 4.2.1.
  479.  
  480. 332Bug>MM 6000;DI <CR>
  481. 00006000    2600    MOVE.L    D0,D3 ? ADDQ.L #1,A3 <CR>
  482.  
  483.  
  484. When a line is terminated with a carriage return, the old source line is erased from the 
  485. terminal screen, the new line is assembled and displayed, and the next instruction in memory 
  486. is disassembled and displayed:
  487.  
  488. 332Bug>MM 6000;DI<CR>
  489. 00006000    528B    ADDQ.L    #1,A3
  490. 00006002    4282    CLR.L    D2 ?
  491.  
  492. If a hardcopy terminal is used, configure port 0 for hardcopy mode (refer to the PF command).  
  493. In hardcopy mode the above example looks like:
  494.  
  495. 332Bug>MM 6000;DI<CR>
  496. 00006000    2600    MOVE.L    D0,D3 ? ADDQ.L #1,A3<CR>
  497. 00006000    528B    ADDQ.L    #1,A3
  498. 00006002    4282    CLR.L    D2 ?
  499.  
  500. Another program line can now be entered.  Program entry continues in like manner until all 
  501. lines have been entered.  A period (.) is used to exit the MM command.  If an error occurs 
  502. during line assembly, the assembler displays the line unassembled with an error message. 
  503. The location being accessed is redisplayed:
  504.  
  505. 332Bug>MM 6000;di <CR>
  506. 00006000    528B    ADDQ.L    #$1,A3? LEA.L 5(A0,D8),A4<CR>
  507. LEA.L 5(A0,D8),A4
  508. BAD COMBINATION OF COMMAND, OPERANDS
  509. 00006000    528B    ADDQ.L    #$1,A3?
  510.  
  511.  
  512. 4.3.3  Entering Branch and Jump Addresses
  513.  
  514. When entering a source line containing a branch instruction (BRA, BGT, BEQ, etc) do not 
  515. enter the offset to the branch's destination in the instruction operand field.  The offset is 
  516. calculated by the assembler.  The user must append the appropriate size extension to the 
  517. branch instruction.
  518.  
  519. To reference a current location in an operand expression use the asterisk (*) character.
  520.  
  521. EXAMPLES:
  522.  
  523. 0000D000    6000BF68    BRA *-4096
  524. 0000D000    60FE    BRA.B *
  525. 0000D000    4EF90000 D000    JMP *
  526. 0000D000    4EF00130 0000D000    JMP (*,A0,D0)
  527.  
  528.  
  529. In the case of forward branches or jumps, the absolute address of the destination may be 
  530. unknown as the program is being entered.  The user may enter an asterisk (*) for branch to 
  531. self in order to reserve space.  After the actual address is discovered, the line containing the 
  532. branch instruction can be re-entered using the correct value.  Enter branch sizes ''B'' or ''W'', 
  533. as opposed to ''S'' and ''L''.
  534.  
  535.  
  536. 4.3.4  Assembler Output/Program Listings
  537.  
  538. Use the MD (Memory Display) command with the ;DI option to obtain a listing of the program.  
  539. The MD command requires the starting address and a line count or ending address to be 
  540. entered in the command line.  When the ;DI option is executed with a line count, the number 
  541. of instructions disassembled and displayed is equal to the line count.
  542.  
  543. Note again, that the listing may not correspond exactly to the program as entered.  As 
  544. discussed in paragraph 4.2.1.3, the disassembler displays in signed hexadecimal any 
  545. number it interprets as an offset of an address register; all other numbers are displayed in 
  546. unsigned hexadecimal.
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.